<template>
  <div>
    <h3>登陆界面</h3>
    手机号:
    <input
      onkeyup="this.value=this.value.replace(/\D/g,'')"
      onafterpaste="this.value=this.value.replace(/\D/g,'')"
      type="text"
      v-model="phone"
    /><br />
    密&nbsp;&nbsp;&nbsp;码: <input type="password" v-model="password" /> <br />
    <button @click="login">登陆</button>
  </div>
</template>

<script>
import { reqLogin } from "@/api/user";
import storage from "@/utils/storageHelper";
export default {
  name: "Login",
  data() {
    return {
      phone: "",
      password: "",
    };
  },
  methods: {
    // 登陆请求函数
    async login() {
      const data = {
        phone: this.phone,
        password: this.password,
      };
      const res = await reqLogin(data);
      console.log(res);
      if (res.code === 200) {
        // 存储token
        storage.localSet({ key: "token", value: res.data.token });
        // 从新跳转回上级页面\
        console.log(this.$route.query.cb)
        this.$router.push(this.$route.query.cb)
      }
    },
  },
  mounted() {
    console.log(this.$route.query.cb);
  },
};
</script>

<style scoped></style>
